const mongoose = require('mongoose');

const CommunityPostSchema = new mongoose.Schema({
  postId: { type: String, required: true },
  title: { type: String, required: true },
  content: { type: String, required: true },
  categoryId: { type: mongoose.Schema.Types.ObjectId, ref: 'PostCategory', required: true },
  coverImage: { type: String },
  videoUrl: { type: String },
  authorId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
  comments: [{
    commentId: { type: String, required: true },
    content: { type: String, required: true },
    authorId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
    createdAt: { type: Date, default: Date.now }
  }],
  viewCount: { type: Number, default: 0 },
  likeCount: { type: Number, default: 0 },
  flag: { type: Boolean, default: true },
  createdAt: { type: Date, default: Date.now },
  updatedAt: { type: Date, default: Date.now }
});

module.exports = mongoose.model('CommunityPost', CommunityPostSchema);